package com.itheima.reggie.mapper;

import com.itheima.reggie.dto.DishDto;
import com.itheima.reggie.entity.Dish;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {
    @Select("select count(*) from dish where category_id=#{id}")
    int findDishWithCategory(long id);

    @Insert("insert into dish values(null,#{name},#{categoryId},#{price},#{code},#{image},#{description},#{status},0,#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")//不理解
    void save(DishDto dishDto);

    List<Dish> findByName(String name);

    @Select("select * from dish where id=#{id}")
    Dish findById(Long id);

    void update(DishDto dishDto);

    @Select("select * from dish where  category_id = #{categoryId} and status=1 order by update_time")
    List<Dish> findByCategoryId(Long categoryId);

    void deleteByIds(@Param("ids") List<Long> ids);

    void updateStatus(@Param("ids") List<Long> ids,@Param("dish") Dish dish,@Param("status")Integer status);
}
